# def response(flow):
#     if 'aweme/v1/user/follower/list/' in flow.request.url:
#         with open('user.txt','a') as f:
#             f.write(flow.response.text+'\n')


import json, pymongo



def response(flow):
    print('p' * 60)
    if 'aweme/v1/user/follower/list/' in flow.request.url:
        followers = json.loads(flow.response.text)['followers']
        dict = {}
        for i in followers:
            dict['share_id'] = i['uid']
            dict['douyin_id'] = i['short_id']
            dict['nickname'] = i['nickname']
            print('插入', dict)
            client = pymongo.MongoClient(host='127.0.0.1', port=27017)
            db = client.douyin
            task_id = db.task_id
            task_id.update({'share_id': dict['share_id']}, dict, True)
            print('good'*30)
